package com.standard.py.springbootwebservicedemo.config;


import com.standard.py.springbootwebservicedemo.service.MPersonService;
import com.standard.py.springbootwebservicedemo.service.impl.MPersonServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * TO DO
 *
 * @author tangjing
 * @date 2021/11/30 10:49
 */
@Configuration
public class CxfConfig {
    //默认servlet路径/*,如果覆写则按照自己定义的来
    @Bean
    public ServletRegistrationBean disServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/services/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    //把实现类交给spring管理，
//    @Bean
//    public AppService appService() {
//        return new AppServiceImpl();
//    }
    @Bean
    public MPersonService mPersonService(){
        return new MPersonServiceImpl();
    }

    //终端路径
    @Bean
    public Endpoint endpoint() {
//        EndpointImpl endpoint = new EndpointImpl(springBus(), appService());
        EndpointImpl endpoint1 = new EndpointImpl(springBus(), mPersonService());
        //测试时，校验器先不要拦截
//        endpoint.getInInterceptors().add(new AuthInterceptor());//添加校验拦截器
//        endpoint.publish("/user");
        endpoint1.publish("/mPerson");
        return endpoint1;
    }
}


